const http = require('http')
const cp = require('child_process')
let child = cp.fork('./server_child.js')
const server = http.createServer()
server.listen(1337, 'localhost', () => {
    child.send('server', server)
    console.log('父进程中的服务器已创建');
    const httpServer = http.createServer()
    httpServer.on('request', (rq, rs) => {
      if (rq.url !== 'favicon.ico') {
        let sum = 0;
        for (let i = 0; i < 1000000; i++) {
          sum += i;
        }
        rs.write('客户端的请求在主进程中被处理')
        rs.end('sum=' + sum)
      }
    })
    httpServer.listen(server)
  console.log('服务启动', server.address());
})